<?php
namespace Lowpress\PressBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\ContainerBuilder,
    Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;

class PressPass implements CompilerPassInterface
{
    public function process(ContainerBuilder $container)
    {
        if (!$container->hasDefinition('lowpress.core.preview') || !$container->hasDefinition('lowpress.core.feed_gatherer')) {
            return;
        }

        $preview_definition = $container->getDefinition('lowpress.core.preview');
        $feed_definition = $container->getDefinition('lowpress.core.feed_gatherer');

        foreach ($container->findTaggedServiceIds('lowpress.core.item') as $id => $attributes)
        {
           $preview_definition->addMethodCall('addPressItemConfigurationId', array($id));
           $feed_definition->addMethodCall('addPressItemConfigurationId', array($id));
        }
    }
}